package github

import "time"

// 练习 4.10: 修改issues程序，根据问题的时间进行分类，比如不到一个月的、不到一年的、超过一年。
func ClassifyIssues(issues []*Issue) map[string][]*Issue {
	classifiedIssues := make(map[string][]*Issue)
	for _, issue := range issues {
		createdAt, _ := time.Parse(time.RFC3339, issue.CreatedAt)
		duration := time.Since(createdAt)
		switch {
		case duration < 30*24*time.Hour:
			classifiedIssues["不到一个月"] = append(classifiedIssues["不到一个月"], issue)
		case duration < 365*24*time.Hour:
			classifiedIssues["不到一年"] = append(classifiedIssues["不到一年"], issue)
		case duration > 365*24*time.Hour:
			classifiedIssues["超过一年"] = append(classifiedIssues["超过一年"], issue)
		}
	}
	return classifiedIssues
}
